/*
 * @lc app=leetcode.cn id=70 lang=javascript
 *
 * [70] 爬楼梯
 */

// @lc code=start
/**
 * @param {number} n
 * @return {number}
 */
// fibonacci 优化 递归转循环推导 dp思维
var climbStairs = function (n) {
  if (n === 1) return 1
  if (n === 2) return 2

  let a = 1
  let b = 2
  let c = 0

  for (let i = 2; i < n; i++) {
    c = a + b
    a = b
    b = c
  }

  return c
}

var climbStairs = function (n) {
  if (n < 0) return false
  if (n < 3) return n
  return climbStairs(n - 1) + climbStairs(n - 2)
}
// @lc code=end
